package lembrete.core.backbeans;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import lembrete.core.beans.Usuario;
import lembrete.core.exceptions.ExcecaoBD;

public class LoginHandler extends SuperHandler /*implements Filter*/{

	private String errorMessage;
	
	private Usuario user;
	
	public LoginHandler() throws FileNotFoundException, ExcecaoBD{
		super();
		setUser(new Usuario());		
	}

	public Usuario getUser() {
		return user;
	}

	public void setUser(Usuario user) {
		this.user = user;
	}
		
	public String logIn() {
		try {
			user = facade.fazLogin(user.getEmail(), user.getPassword());
			FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", user);
			return Web_Util.PASS;
		} catch (Exception e) {
			return Web_Util.FAIL;
		}
	}

	public String getErrorMessage() {
		return this.errorMessage;
	}

	public void setErrorMessage( String errorMessage ) {
		this.errorMessage = errorMessage;
	}
	
	
}
